import java.sql.*;

public class Facility
{
	public static int facilityid = 0;
	public static String facilityname = null;
	public static boolean status = false;
	public static boolean new_record = false;

	public Facility(String name, boolean st)
	{
		facilityname = name;
		status = st;
		new_record = true;
	}

	public Facility(int fid) throws SQLException
	{
		new_record = false;
		facilityid = fid;

		Connector conn = new Connector("select * from facility where facilityid = '" + facilityid + "'");
		ResultSet rs = conn.execute();
		if(rs.first())
		{
			facilityname = rs.getString("facilityname");
			status = rs.getBoolean("status");
		}
		rs.close();
	}
	
	public static boolean insert() throws SQLException
	{
		if(new_record)
		{
			String sql = "insert into facility values(null,"
						+ "'" + facilityname + "',"
						+ status + ")";

			Connector conn = new Connector(sql);
			conn.execute_sql();
			
			return true;
		}
		else
			return false;
	}

	public static boolean update() throws SQLException
	{
		if(!new_record)
		{
			String sql = "update facility set "
						+ "facilityname='" + facilityname + "',"
						+ "status=" + status
						+ " where facilityid='" + facilityid + "'";

			Connector conn = new Connector(sql);
			conn.execute_sql();
			
			return true;
		}
		else
			return false;
	}

	public static boolean delete() throws SQLException
	{
		if(!new_record)
		{
			String sql = "delete from facility where facilityid='" + facilityid + "'";

			Connector conn = new Connector(sql);
			conn.execute_sql();
			
			return true;
		}
		else
			return false;
	}

	public static void setFacilityName(String fn)
	{
		facilityname = fn;
	}

	public static void setStatus(Boolean st)
	{
		status = st;
	}

	public static int getFacilityId()
	{
		return facilityid;
	}

	public static String getFacilityName()
	{
		return facilityname;
	}

	public static Boolean getStatus()
	{
		return status;
	}
}
